<template>
  <div class="admin_page">
    <admin-header></admin-header>
    <admin-side-bar></admin-side-bar>
    <admin-container>
      <el-form inline size="mini" :model="form">
        <el-form-item>
          <el-input
            v-model="form.name"
            prefix-icon="el-icon-search"
            placeholder="name or key"
          ></el-input>
        </el-form-item>
        <el-form-item>
          <el-button type="success">
            搜索
          </el-button>
          <el-button type="primary" @click="() => $refs.add.show()">
            添加
          </el-button>
        </el-form-item>
      </el-form>
      <el-table v-loading="appLoading" border size="mini" :data="data.data">
        <el-table-column label="ID" prop="id"></el-table-column>
        <el-table-column label="参数名称" prop="name"></el-table-column>
        <el-table-column label="参数key" prop="key"></el-table-column>
        <el-table-column
          label="参数value"
          show-overflow-tooltip
          prop="value"
        ></el-table-column>
        <el-table-column label="操作">
          <template slot-scope="{ row }">
            <el-button type="text" size="mini" @click="$refs.add.show(row)">
              修改
            </el-button>
            <el-button type="text" size="mini" @click="del(row)">
              删除
            </el-button>
          </template>
        </el-table-column>
      </el-table>
      <div class="mt10 bg_fff">
        <el-pagination
          :total="page.total"
          :page-size="page.pageSize"
          :current-page="page.pageNum"
          @current-change="pageChange"
        ></el-pagination>
      </div>
    </admin-container>
    <config-add-dialog ref="add" @ok="refresh"></config-add-dialog>
  </div>
</template>

<script>
import AdminHeader from "../../../components/admin/header";
import AdminSideBar from "../../../components/admin/side-bar";
import AdminContainer from "../../../components/admin/container";
import { AppLoadingMixin } from "../../../lib/mixins/app-loading";
import ConfigAddDialog from "../../../components/config/add-dialog";
import { PageMixin } from "../../../lib/mixins/PageMixin";
export default {
  name: "Config",
  components: { ConfigAddDialog, AdminContainer, AdminSideBar, AdminHeader },
  mixins: [AppLoadingMixin, PageMixin],
  data() {
    return {
      form: {}
    };
  },
  computed: {},
  mounted() {
    this.getData();
  },
  methods: {
    del(data) {
      this.$confirm(`是否删除${data.name}?`).then(async () => {
        if (await this.$configService.del(data.id + "")) {
          this.calculatePage("-");
          this.getData();
        }
      });
    },
    async getData() {
      const { page, form } = this;
      this.data = await this.$configService.list({ ...page, ...form });
    }
  }
};
</script>

<style scoped></style>
